import 'package:flutter/material.dart';

class File09HomeGoods extends StatelessWidget {
  const File09HomeGoods({super.key, this.goodsList = const []});

  final List goodsList;

  @override
  Widget build(BuildContext context) {
    return ListView.separated(
      // 父组件是 ListView, 本组件也是 listview嵌套就会报错
      shrinkWrap: true,
      // 设置 shrinkWrap: true 后溢出不滚动, 设置禁止滑动
      physics: const NeverScrollableScrollPhysics(),
      itemBuilder: (context, index) {
        Map item = goodsList[index];
        return Container(
          padding: const EdgeInsets.only(top: 10, bottom: 10),
          height: 120,
          child: Container(
            padding: const EdgeInsets.symmetric(horizontal: 10),
            child: Row(
              spacing: 12,
              children: [
                Image.network(
                  '${item['goods_image']}',
                  height: 120,
                  fit: BoxFit.cover,
                ),
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        "${item['goods_name']}",
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ),
                      Text(
                        "已售${item['goods_sales']}件",
                        style: TextStyle(
                          color: Color.fromARGB(255, 107, 98, 98),
                        ),
                      ),
                      Expanded(
                        child: Row(
                          spacing: 5,
                          children: [
                            Text(
                              "¥${item['goods_price_min']}",
                              style: TextStyle(color: Colors.red),
                            ),
                            Text(
                              "¥${item['line_price_min']}",
                              style: TextStyle(
                                color: Color.fromARGB(255, 107, 98, 98),
                                decoration: TextDecoration.lineThrough,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        );
      },
      separatorBuilder: (BuildContext context, int index) {
        return Container(
          height: 10,
          color: const Color.fromARGB(255, 239, 232, 232),
        );
      },
      itemCount: goodsList.length,
    );
  }
}
